import Cookie from 'js-cookie'
import { REQ_HEADER_KEY } from '@/enums/request-enums'

/**
 * 设置认证信息
 * 
 * @param {Object} auth 认证信息
 * @param {String} authType 认证类型
 * @author LiSong
 * @date 2022-5-13 17:57:54
 */
export function setAuthorization (auth, authType) {
  Cookie.set(REQ_HEADER_KEY, 'Bearer ' + auth.token, {expires: auth.expireAt})
}

/**
 * 移除认证信息
 * 
 * @param {String} authType 
 * @author LiSong
 * @date 2022-5-13 18:03:31
 */
 export function removeAuthorization (authType) {
  Cookie.remove(REQ_HEADER_KEY)
}

/**
 * 检查认证信息
 * 
 * @param {String} authType 
 * @returns {Boolean}
 * @author LiSong
 * @date 2022-5-13 18:05:18
 */
export function checkAuthorization (authType) {
  return Cookie.get(REQ_HEADER_KEY) ? true : false
}
